package com.bigdata.core.transformations

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * map 处理数据是一对一的关系
 * 进入一条数据处理，出来的还是一条数据
 */
object Demo1_map {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local").setAppName("map")
    val sc = new SparkContext(conf)
    sc.setLogLevel("error")

    val infos: RDD[String] = sc.parallelize(Array[String]("hello spark", "hello hdfs", "hello bjsxt"))
    val result: RDD[Array[String]] = infos.map(_.split(" "))

    // 遍历数组并打印
    result.foreach((arr: Array[String]) => {
      println(arr.toList)
    })

    sc.stop()
  }
}
